import * as constants from './constants.js'
import { fromJS } from 'immutable'
import axios from 'axios'

const changeList = (data) => ({
  type: constants.CHANGE_LIST,
  data: fromJS(data),
  totalPage: Math.ceil(data.length / 10)
})
export  const searchFocus = () => ({
  type: constants.SEARCH_FOCUS
})
export const searchBlur = () => ({
  type: constants.SEARCH_BLUR
})
export const getList = () => {
  return (dispatch) => {
    axios.get('/api/headerList.json').then((res) => {
      dispatch(changeList(res.data.data))
    }).catch((err)=> {
      console.log(err)
    })
  }
}
export const changeMouseEnter = () => ({
  type: constants.CHANGE_MOUSE_ENTER
})
export const changeMouseLeave = () => ({
  type: constants.CHANGE_MOUSE_LEAVE
})
export const changePage = (page) => ({
  type: constants.CHANGE_PAGE,
  page
})
export const getItem = (item) => ({
  type: constants.GET_ITEM,
  item
})
export const changeValue = (value) => ({
  type: constants.CHANGE_VALUE,
  value
})